<?php
# MantisBT - a php based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.

	/**
	 * @package MantisBT
	 * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
	 * @copyright Copyright (C) 2002 - 2010  MantisBT Team - mantisbt-dev@lists.sourceforge.net
	 * @link http://www.mantisbt.org
	 */
	 /**
	  * MantisBT Core API's
	  */
	require_once( 'core.php' );
	require_once( 'current_user_api.php' );
	require_once( 'compress_api.php' );
	require_once( 'filter_api.php' );
	require_once( 'last_visited_api.php' );

	//require_once( 'communication_api.php' );
	
	//requestmysql(mantis_care_report_table);
	auth_ensure_user_authenticated();

	$t_current_user_name = current_user_get_field( 'username' );
	$t_current_real_name = current_user_get_field( 'realname' );
	
	# Improve performance by caching category data in one pass
	category_get_all_rows( helper_get_current_project() );

	compress_enable();

	# don't index my view page
	html_robots_noindex();

	html_page_top1( lang_get( 'my_view_link' ) );

	if ( current_user_get_pref( 'refresh_delay' ) > 0 ) {
		html_meta_redirect( 'my_view_page.php', current_user_get_pref( 'refresh_delay' )*60 );
	}

	html_page_top2();

	print_recently_visited();

	$f_page_number		= gpc_get_int( 'page_number', 1 );

	$t_per_page = config_get( 'my_view_bug_count' );
	$t_bug_count = null;
	$t_page_count = null;

	$t_boxes = config_get( 'my_view_boxes' );
	asort ($t_boxes);
	reset ($t_boxes);
	#print_r ($t_boxes);

	$t_project_id = helper_get_current_project();
?>
<?php 

include('alert_user.php');
$do = $_GET['do'];
$action = $_GET['a'];
echo '<br>Trung tâm Dịch vụ khách hàng<hr>	<div align="center">
<table border=0 cellspacing="3" cellpadding="0" width=100%>
	<tr>
		<td valign=top>
		<table style="border:1px solid black;width:100%;height:20px;"class=ttt><tr>
			<td valign=top width=20%>
					<div style="background:#D5D5FF"><b>Danh mục</b></div><hr>
					<a href="my_customer_page.php" title="Home.DVKH">Home</a> <br>
					<a href="?do=addcare" title="Nhập thông tin khách hàng">Add care</a> <br>
						<a href="?do=search">Tìm kiếm</a> <br>
					<a href="?do=atme" title="Khách hàng chuyển tới tôi">Khách hàng chuyển tới tôi</a><br>
					<a href="?do=viewall" title="Liệt kê danh sách khách hàng">View all</a> <br>
					<a href="?do=viewcms">View CMS</a> <br>
					<a href="?do=viewme">View me</a> <br>
					<a href="?do=monitor" title="Liệt kê khách hàng đang theo dõi">View all monitor</a> <br>
					<a href="?do=recall" title="Liệt kê khách hàng chờ gọi lại">View all recall</a> <br>
					<a href="?do=creport">Xuất báo cáo</a> <br>
					<a href="?do=download">Download</a> <br> 
					<a href="?do=viewagent">Liệt kê khách hàng Đại lí - CTV</a> <br>
					<a href="?do=managent&a=view">Quản lí & chăm sóc đại lý - CTV</a> <br>
					<a href="?do=sumst">Summary status</a> <br>
			</td>';
		
		//Add thông tin khách hàng
		if ($do == addcare)
		{			
			echo '<td valign=top width=60%>
			<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/style.css" type="text/css">
					<title>Nhập contact khách hàng</title> 
					<style> 
					fieldset{display: none; padding: 10px;} 
					</style> 
					<script type="text/javascript"> 
					function toggleSet(rad) 
					{ 
					  var type = rad.value; 
					  for(var k=0,elm;elm=rad.form.elements[k];k++) 
						if(elm.className=="item") 
						  elm.style.display = elm.id==type? "inline":""; 
					} 
					</script> 
					</head>
					<body>		
						<form name="care" action="?do=pdata" method="post">
						<table border=1 cellpadding=0 cellspacing=0 style="border-collapse:collapse" width=100%>
						<tr><td bgcolor=D5D5FF><b>Nhập thông tin khách hàng</b></td></tr><tr><td>
						<table border=0>
							<tr><td>Mã khách hàng:</td><td><input name="spcode" type="spcode" style="border:2px solid #DADADA;height:25px;"></td><td></td><td></td></tr>
							<tr><td>Tên khách hàng :</td><td><input name="name" type="name" style="border:2px solid #DADADA;height:25px;"></td><td>Phone :</td><td><input name="phone" type="phone" style="border:2px solid #DADADA;height:25px;"></td></tr>
							<tr>
							<td>Email :</td><td><input name="email" type="email" style="border:2px solid #DADADA;height:25px;"></td>
							<td> Giới tính : </td><td><Select name="sex" style="border:2px solid #DADADA;height:25px;">
								<option value =male>Male</option>
								<option value =female>Female</option>
								</select><br></td>
							</tr>
							<tr>
							<td>Địa chỉ :</td><td><input name="address" type="address" style="border:2px solid #DADADA;height:25px;"><br></td>
							<td> Tỉnh/TP : </td><td><Select name="city" style="border:2px solid #DADADA;height:25px;">
									<option value =default>Chưa xác định</option>
									<option value =angiang>An Giang</option>
									<option value =brvt>Bà rịa vũng tàu</option>
									<option value =bacgiang>Bắc Giang</option>
									<option value =baclieu>bạc liêu</option>
									<option value =baccan>bắc cạn</option>
									<option value =bacninh>bắc ninh</option>
									<option value =bentre>bến tre</option>
									<option value =binhdinh>bình định</option>
									<option value =binhduong>bình dương</option>
									<option value =binhphuoc>bình phước</option>
									<option value =binhthuan>bình thuận</option>
									<option value =camau>cà mau</option>
									<option value =caobang>cao bằng</option>
									<option value =cantho>cần thơ</option>
									<option value =danang>đà nẵng</option>
									<option value =dl>đắk lắk</option>
									<option value =dn>đắk nông</option>
									<option value =dienbien>điện biên</option>
									<option value =dongnai>đồng nai</option>
									<option value =dongthap>đồng tháp</option>
									<option value =gialai>gia lai</option>
									<option value =hagiang>hà giang</option>
									<option value =hanam>hà nam</option>
									<option value =hanoi>hà nội</option>
									<option value =hatinh>hà tĩnh</option>
									<option value =haiduong>hải dương</option>
									<option value =haiphong>hải phòng</option>
									<option value =haugiang>hậu giang</option>
									<option value =hoabinh>hòa bình</option>
									<option value =hcm>hcm</option>
									<option value =hungyen>hưng yên</option>
									<option value =khanhhoa>khánh hòa</option>
									<option value =kiengiang>kiên giang</option>
									<option value =kontum>kon tum</option>
									<option value =laichau>lai châu</option>
									<option value =lamdong>lam dong</option>
									<option value =langson>lạng sơn</option>
									<option value =laocai>lào cai</option>
									<option value =longan>long an</option>
									<option value =namdinh>nam định</option>
									<option value =nghean>nghệ an</option>
									<option value =ninhbinh>ninh bình</option>
									<option value =ninhthuan>ninh thuận</option>
									<option value =phutho>phú thọ</option>
									<option value =phuyen>phú yên</option>
									<option value =quangbinh>quảng bình</option>
									<option value =quangnam>quảng nam</option>
									<option value =quangngai>quảng ngãi</option>
									<option value =quangninh>quảng ninh</option>
									<option value =quangtri>quảng trị</option>
									<option value =soctrang>sóc trăng</option>
									<option value =sonla>sơn la</option>
									<option value =tayninh>tây ninh</option>
									<option value =thaibinh>thái bình</option>
									<option value =thainguyen>thái nguyên</option>
									<option value =thanhhoa>thanh hóa</option>
									<option value =thuathienhue>thừa thiên huế</option>
									<option value =tiengiang>tiền giang</option>
									<option value =travinh>trà vinh</option>
									<option value =tuyenquang>tuyên quang</option>
									<option value =vinhlong>vĩnh long</option>
									<option value =vinhphuc>vĩnh phúc</option>
									<option value =yenbai>yên bái</option>	
								</select><br></td></tr>
							<tr>
							<td>Serial/lô :</td> <td> <input name="serial" type="serial" style="border:2px solid #DADADA;width:60px;height:25px;"> - 
							<input name="lo" type="lo" style="border:2px solid #DADADA;width:60px;height:25px;"><br></td>
							<td> Đối tượng: </td><td><Select name="dt" style="border:2px solid #DADADA;height:25px;">
								<option value =user>Khách hàng cá nhân</option>
								<option value =agent>Đại lí</option>
								</select><br></td></tr>
						</td></tr></table>
						</table>
						<br>
						<table border=1 cellpadding=0 cellspacing=0 style="border-collapse:collapse" width=100%>
						<tr><td bgcolor=D5D5FF><b>Nhập thông tin phản hồi</b></td></tr>
						<tr><td>
						<table>
							<tr>
							<td>Dạng cuộc gọi</td><td><Select name="object" style="border:2px solid #DADADA;height:25px;">
								<option value =incomming>Gọi đến</option>
								<option value =outgoing>Gọi đi</option>
								<option value =email>Email in</option>
								</select><br></td></tr>
							<tr>
							<td> Phản hồi về:</td><td><Select name="status" style="border:2px solid #DADADA;height:25px;">
								<option value =virus>Dính virus</option>
								<option value =cms>CMC Mobile Security</option>
								<option value =using>Cách sử dụng sản phẩm</option>
								<option value =ProductError>Lỗi sản phẩm</option>
								<option value =License>Liên quan đến bản quyền</option>
								<option value =ComputerError>Sự cố máy tính</option>
								<option value =CallError>Máy bận/Không liên lạc được/SĐT sai</option>
								<option value =nopro>Không gặp vấn đề gì</option>
								<option value =other>Các vấn đề khác</option>
								</select><br></td></tr>
							<tr>
							<td> Hoàn thành<input type="radio" name="itemtype" value="complete"  onclick="toggleSet(this)"></td>
							<td>  Chuyển tiếp <input type="radio" name="itemtype" value="move" onClick="toggleSet(this)"> </td> 
							</tr>
							<tr> <td></td>
								<td>
								  <fieldset id="complete" class="item"> 
									<legend>Complete</legend> 
									Đã xử lí xong
								  </fieldset>
								  <fieldset id="move" class="item"> 
									<legend>Chuyển khách hàng cho kĩ thuật khác</legend> 
									Kĩ thuật tiếp nhận <Select name="receiver">';
									$req = mysql_query("select username from `mantis_user_table` where access_level='25'");
									while ($row = mysql_fetch_array($req)){
									if ($row['username'] != $seller)
									{ echo'<option value ='.$row['username'].'>'.$row['username'].'</option>';}
									}
								echo '
								</select><br> 
								  </fieldset> 
								  </td>
							 </tr>
							<tr>
							<td valign=top>Phản hồi:</td><td><textarea name="confirm" type="confirm" cols="56" rows="4" style="border:2px solid #DADADA;height:100px;"></textarea><br></td>
							</tr>
							<tr>
							<td valign=top>Cách xử lí:</td><td><textarea name="process" type="process" cols="56" rows="4" style="border:2px solid #DADADA;height:100px;"></textarea></tr>
							<tr>
							<td><input name="submit" type="submit" value="submit"></td>
							</tr>
							</table>
							</td></tr></table>
							</form> 
							</body></html>
							</td>';
						}
						
//Ghi dữ liệu khách hàng vào data
		if ($do == pdata)
		{
			echo '<td width=60% valign=top><html xmlns="http://www.w3.org/1999/xhtml">
						<head>
						<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
						<title>Seller management Systems</title>
						<link rel="stylesheet" href="css/style.css" type="text/css">
						</head>
						<body>
						';
						$seller = $t_current_user_name;
						//send information from form
						$spcode = $_POST['spcode'];
						$name = $_POST['name'];
						$phone = $_POST['phone'];
						$email = $_POST['email'];
						$sex = $_POST['sex'];
						$address = $_POST['address'];
						$city = $_POST['city'];
						$serial = $_POST['serial'];
						$lo = $_POST['lo'];
						$dt = $_POST['dt'];
						$object = $_POST['object'];
						$status = $_POST['status'];
						$state = $_POST['itemtype'];
						$confirm = $_POST['confirm'];
						$process = $_POST['process'];
						$receiver = $_POST['receiver'];
						$time = date("H:i:s, d-m-Y");
						$start_time = time();
						
						if (preg_match('/^\(?[0]{1}[0-9]{2}\)?|[0-9]{3,3}?[ ][0-9]{3,3}?[0-9]{4,4}$/', $phone)) 
						
						{ 	//Them so vao Serial/Lo
							if(strlen($serial) == 4) {	$serial = '0'.$serial;}
							if(strlen($serial) == 3) {	$serial = '00'.$serial;}
							if(strlen($serial) == 2) {	$serial = '000'.$serial;}
							if(strlen($serial) == 1) {	$serial = '0000'.$serial;}
							//Insert contact khách hàng
								mysql_query("
								insert into `$db`.`contact` 
								(name, phone, email, address) 											
								values('$name','$phone','$email','$address')");
								echo '<div align=center><table border=1><tr><td align=center>';
							if ($state == complete){
							//Insert thong tin cham soc khach hang
								$mark = complete;
								mysql_query("
								insert into `mantis_care_report_table` 
								(spcode, name, phone, email, sex, address, city, serial , lo, dt, object, status, state, confirm, process, mark ,start_time, carer) 											
								values('$spcode','$name','$phone','$email','$sex','$address','$city','$serial','$lo','$dt','$object','$status','$state','$confirm','$process', '$mark','$start_time','$seller')");
								echo "Bạn đã nhập dữ liệu khách hàng <b>".$name."</b> với số Serial/lo:[<b>".$serial."/".$lo."</b>] thành công<br>";
								echo "Check danh sách khách hàng chăm sóc trong ngày hôm nay";
								echo  "<div align=center><br><a href='?do=viewall'>[LIST]</a> | <a href='logout_page.php'>[Logout]</a></div>";
								}
							else 
							{							
							
							if ($state == move)
								{
								$mark = processing;
								
								mysql_query("
								insert into `mantis_care_report_table` 
								(spcode, name, phone, email, sex, address, city, serial , lo, dt, object, status, state, confirm, process, mark ,start_time, carer, receiver) 											
								values('$spcode','$name','$phone','$email','$sex','$address','$city','$serial','$lo','$dt','$object','$status','$state','$confirm','$process', '$mark','$start_time','$seller','$receiver')");
								echo "Bạn đã nhập dữ liệu khách hàng <b>".$name."</b> với số Serial/lo:[<b>".$serial."/".$lo."</b>] thành công<br>";
								echo "Check danh sách khách hàng chăm sóc trong ngày hôm nay";
								echo  "<div align=center><br><a href='?do=viewall'>[LIST]</a> | <a href='logout_page.php'>[Logout]</a></div>";
								}
								else {echo 'chua chon trang thai kia ku';}
							}
							echo '</td></tr></table></div>';	}
						else
							{ 
							echo "<div align=left>
							Bạn nhập sai số điện thoại rồi, nhập lại ngay<br>
							<b><u>Chú ý:</u></b><br>
							#Không có dấu cách ở đầu<br>#Không được thiếu đầu 0 ở đầu</div>";
							}
		echo '</td>';				
		}
		
		//Hiển thị toàn bộ khách hàng được assign to me
		if ($do == atme)
		{
		$req = mysql_query("select * from `mantis_care_report_table` where `receiver`='$t_current_user_name' and `state`='move'");
		include('includeM.php');
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									
									// Max a last update
												$qr = "SELECT MAX(last_updated), cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());

												// Print out result
												while($row = mysql_fetch_array($resultt))
												{
													$cid = $row['cid'];
													$note = $row['note'];
													$resolver = $row['resolver'];
													$last_updated = (date("d-m-Y H:i",$row['MAX(last_updated)']));
												}	
									echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>'.$object.'</td>
										<td width=10%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>'.$last_updated.'</td>
										<td width=7%   class='.$state.'>'.$carer.'</td>
										<td width=7%   class='.$state.'>'.$resolver.'</td>
										<td width=22%  class='.$state.'c>'.substr($confirm,0,100).'</td>
										</tr>';					
							}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		//Hiện thị toàn bộ danh khách hàng
		if ($do == viewall)
		{	
			$req = mysql_query("select * from `mantis_care_report_table` ORDER BY id DESC");
			
			echo ' <td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Liệt kê tất cả khách hàng trong ngày</b></div><hr>
				<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=0 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td> 
							<table border=0 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% class=ttt>  
									<tr>
										<td width=2% bgcolor=#CECEFF><b>ID</td>
										<td width=10% bgcolor=#CECEFF><b>Name</td>
										<td width=27% bgcolor=#CECEFF><b>Phản hồi/xử lí</td>
										<td width=7% bgcolor=#CECEFF><b>sTime</td>
										<td width=7% bgcolor=#CECEFF><b>uTime</td>
										<td width=7% bgcolor=#CECEFF><b>Khởi tạo</td>
										<td width=7% bgcolor=#CECEFF><b>Lastsp</td>
										<td width=10% bgcolor=#CECEFF><b>Trạng thái</td>
									</tr>';
							$i = 0;
								while ($row = mysql_fetch_array($req))
					{	
								$id	= $row['id'];
								$spcode = $row['spcode'];
								$name = $row['name'];
								$phone = $row['phone'];
								$email = $row['email'];
								$sex = $row['sex'];
								$address = $row['address'];
								$city = $row['city'];
								$serial = $row['serial'];
								$lo = $row['lo'];
								$object = $row['object'];
								$status = $row['status'];
								$state = $row['state'];
								$confirm = $row['confirm'];
								$process = $row['process'];
								$receiver = $row['receiver'];
								$carer = $row['carer'];
								$start_time = (date("d-m-Y",$row['start_time']));
								$QueryDay = (date("d",$row['start_time']));
								$QueryCurrentDay = date("d");
								$QueryCurrentMonth = (date("m",$row['start_time']));
								$QueryMonth = date("m");
								$QueryCurrentYear = (date("Y",$row['start_time']));
								$QueryYear = date("Y");
						if (($QueryDay == $QueryCurrentDay) and ($QueryCurrentMonth == $QueryMonth) and ($QueryCurrentYear == $QueryYear))
						{
							$i++;
							if ($status == cms) {$m = '(M)';} else {$m ='';}
							echo '<tr>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.$i.'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$name.' <font color=red><b>'.$m.'</b></font> ['.$phone.']</td>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.nl2br($confirm).'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$start_time.'</td>';
							echo '<td style="border-bottom:1px solid #666666;">';
							// Max a last update
							$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
							$resultt = mysql_query($qr) or die(mysql_error());
							$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
							$resultqt = mysql_query($qt) or die(mysql_error());
							// Print out result
							while($row = mysql_fetch_array($resultt))
							{
								$resolver = $row['resolver'];
								$last_updated = (date("d-m-Y H:i:s",$row['MAX(last_updated)']));
								echo $last_updated;
							}	
							echo '</td>
								<td style="border-bottom:1px solid #666666;">'.$carer.'</td>
								<td style="border-bottom:1px solid #666666;">';
								while($row = mysql_fetch_array($resultqt))
									{
									$resolver = $row['resolver'];
									echo $resolver;
									}	echo'</td>
							<td style="border-bottom:1px solid #666666;" class="'.$state.'">'.$state.' (<a href="")>'.$receiver.'</a>)</td>
							</tr>';					
						}
					
					}
		
			echo '				</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html></td>';
		
		}
		
		//Hiện thị toàn bộ danh khách hàng sử dụng CMC Mobile Security
		if ($do == viewcms)
		{
			$t_current_user_name = current_user_get_field( 'username' );
			$i = 0;
			$req = mysql_query("select * from `mantis_care_report_table` where status='cms' ORDER BY id DESC");
			include('includeM.php');
				while ($row = mysql_fetch_array($req))
				{	
					$id	= $row['id'];
					$spcode = $row['spcode'];
					$name = $row['name'];
					$phone = $row['phone'];
					$email = $row['email'];
					$sex = $row['sex'];
					$address = $row['address'];
					$city = $row['city'];
					$serial = $row['serial'];
					$lo = $row['lo'];
					$object = $row['object'];
					$status = $row['status'];
					$state = $row['state'];
					$confirm = $row['confirm'];
					$process = $row['process'];
					$receiver = $row['receiver'];
					$carer = $row['carer'];
					$start_time = (date("d-m-Y",$row['start_time']));
					$QueryDay = (date("d",$row['start_time']));
					$QueryCurrentDay = date("d");
					$QueryCurrentMonth = (date("m",$row['start_time']));
					$QueryMonth = date("m");
					$QueryCurrentYear = (date("Y",$row['start_time']));
					$QueryYear = date("Y");
					$i++;
					if ($status == cms) {$m = '(M)';} else {$m ='';}
					echo '<tr>
					<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.$i.'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$name.' <font color=red><b>'.$m.'</b></font>  ['.$phone.']</td>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.nl2br($confirm).'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$start_time.'</td>';
					$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
					$resultqt = mysql_query($qt) or die(mysql_error());
					// Print out result
					
					echo '<td style="border-bottom:1px solid #666666;">'.$carer.'</td>
					<td class='.$state.' style="border-bottom:1px solid #666666;">'.$state.' (<a href="")>'.$receiver.'</a>)</td>
					</tr>';					
				}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		
		//Hiện thị toàn bộ danh khách hàng
		if ($do == viewme)
		{
			$t_current_user_name = current_user_get_field( 'username' );
			$i = 0;
			$req = mysql_query("select * from `mantis_care_report_table` where carer='$t_current_user_name' ORDER BY id DESC");
			include('includeM.php');
				while ($row = mysql_fetch_array($req))
				{	
					$id	= $row['id'];
					$spcode = $row['spcode'];
					$name = $row['name'];
					$phone = $row['phone'];
					$email = $row['email'];
					$sex = $row['sex'];
					$address = $row['address'];
					$city = $row['city'];
					$serial = $row['serial'];
					$lo = $row['lo'];
					$object = $row['object'];
					$status = $row['status'];
					$state = $row['state'];
					$confirm = $row['confirm'];
					$process = $row['process'];
					$receiver = $row['receiver'];
					$carer = $row['carer'];
					$start_time = (date("d-m-Y",$row['start_time']));
					$QueryDay = (date("d",$row['start_time']));
					$QueryCurrentDay = date("d");
					$QueryCurrentMonth = (date("m",$row['start_time']));
					$QueryMonth = date("m");
					$QueryCurrentYear = (date("Y",$row['start_time']));
					$QueryYear = date("Y");
					$i++;
					echo '<tr>
					<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.$i.'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$name.' ['.$phone.']</td>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.nl2br($confirm).'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$start_time.'</td>';
					$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
					$resultqt = mysql_query($qt) or die(mysql_error());
					// Print out result
					
					echo '<td style="border-bottom:1px solid #666666;">'.$carer.'</td>
					<td class='.$state.' style="border-bottom:1px solid #666666;">'.$state.' (<a href="")>'.$receiver.'</a>)</td>
					</tr>';					
				}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == monitor)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where state='monitor' ORDER BY id DESC");
			include('includeM.php');
							$i =0;
							while ($row = mysql_fetch_array($req))
							{	
								include('includeB.php');
							}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == recall)
		{
			$req = mysql_query("select * from `mantis_care_report_table` where state='recall' ORDER BY id DESC");
			include('includeM.php');
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{	
								include('includeB.php');
							}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html>';
		}
		
		if ($do == creport)
		{	
			$er = current_user_get_field( 'access_level' );
			echo '<td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Liệt kê tất cả khách hàng trong ngày</div><hr><table>
			<b>Xuất báo cáo:</b><br>
			<form name=xreport method=POST action="?do=xreport&value=x">
			<tr><td>Ngày: </td><td> From <input name=sDay type=sDay style="width:40px"> - <input name=eDay type=eDay style="width:40px"><br></td></tr>
			<tr><td>Tháng:</td><td> From <input name=sMonth type=sMonth style="width:40px"> - <input name=eMonth type=eMonth style="width:40px">  <br></td></tr>
			<tr><td>Năm: </td><td> From <input name=sYear type=sYear style="width:40px"> - <input name=eYear type=eYear style="width:40px"><br></td></tr>
			';
			if ($er == 90)
			{ echo '<tr><td>Agent (Ex: nhungtth)</td><td><input name=cNameAgent type=cNameAgent></td></tr>';}
			echo 
			'<tr><td><input name=submit type=submit value=submit></td></tr>
			</form>			
			</table>
			';
		}
		
		if (($do == xreport) and ($_GET['value'] == x))
		{
			$sDay = $_POST['sDay'];
			$sMonth = $_POST['sMonth'];
			$sYear = $_POST['sYear'];
			$eDay = $_POST['eDay'];
			$eMonth = $_POST['eMonth'];
			$eYear = $_POST['eYear'];
			$username = $_POST['cNameAgent'];
			echo '<td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Liệt kê tất cả khách hàng trong ngày</div><hr>
				<input type="button" onClick="window.print()" value="In báo cáo"/>
				<br><br>
				<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% > 
						<tr>
							<td>  <b>Viewing all report</b> [ Print Reports ]  [ CSV Export ]  [ Excel Export ]<br><br>    
								<table border=1 bordercolor=black cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
									<tr>
										<td width=4%>ID</td>
										<td width=4%>ED</td>
										<td width=10%><a href="">NAME</a></td>
										<td width=10%><a href="">CATEGORY</a></td>
										<td width=7%><a href="">STATUS</a></td>
										<td width=7%>Start time</td>
										<td width=7%>Start Supporter</td>
										<td width=20%>Phản hồi</td>
										<td width=20%>Xử lí</td>
									</tr>
								</table>
								<table border=1 bordercolor=black cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%>			
								';
							$i = 0;
							$er = current_user_get_field( 'access_level' );
					if ($er <90)
					{
							$CheckReportOfMonth = mysql_query("select * from `mantis_care_report_table` WHERE carer='$t_current_user_name' 
									AND from_unixtime(start_time, '%e') >='$sDay' AND from_unixtime(start_time, '%e')<='$eDay'
									AND from_unixtime(start_time, '%c') >='$sMonth' AND from_unixtime(start_time, '%c')<='$eMonth'
									AND from_unixtime(start_time, '%Y') >='$sYear' AND from_unixtime(start_time, '%Y')<='$eYear'
									ORDER By id ASC
							");
					}
					else 
					{
							$CheckReportOfMonth = mysql_query("select * from `mantis_care_report_table` WHERE carer='$username' 
									AND from_unixtime(start_time, '%e') >='$sDay' AND from_unixtime(start_time, '%e')<='$eDay'
									AND from_unixtime(start_time, '%c') >='$sMonth' AND from_unixtime(start_time, '%c')<='$eMonth'
									AND from_unixtime(start_time, '%Y') >='$sYear' AND from_unixtime(start_time, '%Y')<='$eYear'
									ORDER By id ASC
							");
					}
					
					while ($row = mysql_fetch_array($CheckReportOfMonth))
					{
									$i++;
									$id	= $row['id'];
									$name = $row['name'];
									$phone = $row['phone'];
									$email = $row['email'];
									$sex = $row['sex'];
									$address = $row['address'];
									$city = $row['city'];
									$serial = $row['serial'];
									$lo = $row['lo'];
									$object = $row['object'];
									$status = $row['status'];
									$state = $row['state'];
									$confirm = $row['confirm'];
									$process = $row['process'];
									$receiver = $row['receiver'];
									$carer = $row['carer'];
									$start_time = (date("d-m-Y H:i:s",$row['start_time']));
									$QueryTime = (date("H",$row['start_time']));
									$QueryDay = (date("d",$row['start_time']));
									$QueryMonth = (date("m",$row['start_time']));
									$QueryYear = (date("y",$row['start_time']));
								
							// Max a last update

												$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
												$resultt = mysql_query($qr) or die(mysql_error());
												
												$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
												$resultqt = mysql_query($qt) or die(mysql_error());
												// Print out result
								echo '<tr>
										<td width=4%   class='.$state.'>'.$i.'</td>
										<td width=4%   class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$id.'</a></td>
										<td width=10%  class='.$state.'>'.$name.'</td>
										<td width=10%  class='.$state.'>['.$status.']<br>'.$object.'</td>
										<td width=7%  class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
										<td width=7%   class='.$state.'>'.$start_time.'</td>
										<td width=7%   class='.$state.'>'.$carer.'</td>
										<td width=20%  class='.$state.'c>'.nl2br(substr($confirm,0,300)).'</td>
										<td width=20%  class='.$state.'c>'.nl2br(substr($process,0,300)).'</td>
										</tr>';	
					} 
				
						echo '</table>';
				}
		
		if ($do == sumst)
		{
			
			echo '<td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Tổng kết theo dạng phản hồi của khách hàng</b></div><hr>';
			$t_today = date("d");
			$t_month = date("m");
			$t_month1 = date("F - Y");
			$t_year	 = date("Y");
			$t_hour	 = date("H");
			echo "<div style='background-color:#CCCCCC;margin-bottom:5px;'><b>[".$t_month1."] Status request </b></div>
				<table border=1 style='border: 1px solid black; float: left; width: 25%; height: 1em; border-collapse:collapse'>
				<tr><td><b>Monthly</td></tr>
				<tr><td><b>Dính virus</td></tr>
				<tr><td><b>Cách sử dụng sản phẩm</td></tr>
				<tr><td><b>Lỗi sản phẩm</td></tr>
				<tr><td><b>Liên quan đến bản quyền</td></tr>
				<tr><td><b>Sự cố máy tính</td></tr>
				<tr><td><b>Máy bận/notconnect/SĐT sai</td></tr>
				<tr><td><b>Không gặp vấn đề gì</td></tr>
				<tr><td><b>Các vấn đề khác</td></tr>
				</table>";
			for ($i=1;$i<=$t_month;$i++)
					{
					$sVirus = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='virus'");
					$sUsing = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='using'");
					$sProductError = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='ProductError'");
					$sLicense = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='License'");
					$sComputerError = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='ComputerError'");
					$sCallError = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='CallError'");
					$snopro = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='nopro'");
					$sOther = mysql_query("Select count(name) from mantis_care_report_table where from_unixtime(start_time, '%c')=$i and from_unixtime(start_time, '%Y')='$t_year' and status='other'");

					echo "<table border=1 style='border: 1px solid black; float: left; width: 40px; height: 1em; border-collapse:collapse'>
							<tr>";echo "<td class=monthly>".$i."-".$t_year."</td>";echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sVirus))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=virus'>".$row['count(name)']."</a>";}
							echo "</td></tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sUsing))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=using'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sProductError)){
							echo "<a href='view_filters_care_page.php?do=list&time=$i&order=ProductError'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sLicense))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=License'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sComputerError))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=ComputerError'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sCallError))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=CallError'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($snopro))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=nopro'>".$row['count(name)']."</a>";}echo "</tr>
							<tr><td class=monthly>";while ($row = mysql_fetch_array($sOther))
							{echo "<a href='view_filters_care_page.php?do=list&time=$i&order=Other'>".$row['count(name)']."</a>";}echo "</tr>
						</table>";
					}
			
			echo '</td>';
		}
		
		if ($do == download)
		{
			echo '<td width=60% valign=top>
				<div style="background:#D5D5FF;"><b>Khu vực download công cụ hỗ trợ | <a href="?do=download&a=addap">Add</a></b></div><hr>';
				$sqlfu = mysql_query('SELECT id,filename,mdfive,file_type,filesize,from_unixtime(date_added), user_id,folder FROM mantis_care_file_table WHERE care_id="2468" ORDER BY `date_added` DESC ');
				$b = 1;
				$hit_count = @file_get_contents('count.txt'); // read the hit count from file
				
				if ($action == addap)
					{echo '
					<form action="?do=upload" method="post" enctype="multipart/form-data">
								<table border=1 cellpadding=0 cellspacing=0 style="border-collapse:collapse" width=100%><tr><td>
								<table border=0 cellpadding=0 cellspacing=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF>
								<tr><td width=20%>Select File<br>(Maximum size: 5,000k)</td></td><td> <input type="file"  name="ufile" /> <input type="submit" value="Upload file" /></td></tr>
								</table></td></tr></table>
								</form><br>';}
				While ($row = mysql_fetch_array($sqlfu))
				{	
					$id = $row['id'];
					$filename    = $row['filename'];
					$file_type   = $row['file_type'];             
					$filesize = $row['filesize'];
					$date_added = $row['from_unixtime(date_added)'];
					$care_id = $row['care_id'];
					$user_id       = $row['user_id'];
					$folder        = $row['folder'];
					$mdfive= $row['mdfive'];
					$url = ''.$folder;
					echo '<b>'.$b.' | '. $filename.'</b> | '.$mdfive.' | '.$date_added.' | '.$user_id.' | <a href="'.$url.'">Download</a> 
					| <a href="?do=download&a=delapp&aid='.$id.'">Del</a><br><br>';
					$b++;
				}
				
				if ($action == delapp)
					{
					$aid = $_GET['aid'];
					mysql_query("DELETE FROM `mantis_care_file_table` WHERE `id` = '$aid'");
					header('Location: ?do=download');
					}
			echo '</td>';
		}
		
		if ($do == upload)
		{
		
			if($_FILES['ufile']['name'])
			{
			//if no errors...
			if(!$_FILES['ufile']['error'])
				{
				$id = $_GET['id'];
				$SafeFile = $_FILES['ufile']['name'];
				$SafeFile = str_replace("#", "No.", $SafeFile);
				$SafeFile = str_replace("$", "Dollar", $SafeFile);
				$SafeFile = str_replace("%", "Percent", $SafeFile);
				$SafeFile = str_replace("^", "", $SafeFile);
				$SafeFile = str_replace("&", "and", $SafeFile);
				$SafeFile = str_replace("*", "", $SafeFile);
				$SafeFile = str_replace("?", "", $SafeFile);
				$theFileName = $_FILES['ufile']['name'];
				$t_current_user_name = current_user_get_field( 'username' );
						// random 4 digit to add to our file name
						// some people use date and time in stead of random digit
						$random_digit=rand(00000000000000,99999999999999);
						//combine random digit to you file name to create new file name
						$new_file_name=$theFileName;
				$path= "upload/".$new_file_name;
				
				if($ufile != none)
				{ //AS LONG AS A FILE WAS SELECTED...

				if(copy($_FILES['ufile']['tmp_name'], $path))//IF IT HAS BEEN COPIED...
				{ 
					//GET FILE NAME
					$theFileName = $_FILES['ufile']['name'];

					//GET FILE SIZE
					$theFileSize = $_FILES['ufile']['size'];
					
					//GET FILE SIZE
					$theFileType = $_FILES['ufile']['type'];
					

					if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
						$theDiv = $theFileSize / 1000000;
						$theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
					} else { //OTHERWISE DISPLAY AS KB
						$theDiv = $theFileSize / 1000;
						$theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
					}
					
					$pjcare_id = $id;
					$user_id = $t_current_user_name;
					$date_added = time();
					$mdfive = md5_file($path);
					mysql_query("insert into `mantis_care_file_table` 
						(filename, mdfive, file_type,filesize,date_added,care_id, pjcare_id, user_id, folder) 
						values ('$theFileName','$mdfive','$theFileType','$theFileSize','$date_added','2468','$pjcare_id','$user_id','$path')");
					header('Location: ?do=download');
						
				} else 
					{

					//PRINT AN ERROR IF THE FILE COULD NOT BE COPIED
						echo '
						<table cellpadding="5" width="80%">
						<tr>
						<td align="Center" colspan="2"><font color=\"#C80000\"><b>File could not be uploaded</b></font></td>
						</tr></table>';
					}
				}
				}
			}

		}
		
		//Tìm kiếm khách hàng cá nhân
		if ($do == search)
		{
			echo '<td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Tìm kiếm thông tin khách hàng cá nhân</div><hr>
				<form action="?do=sc" method="POST" name="searching">
					<b>Tìm kiếm theo user:</b>
					<Select name="search">
					<option value=fspcode>Tìm theo mã khách hàng (Ex: 158)</option>
					<option value=cphone>Tìm theo số điện thoại (Ex: 091234567)</option>
					<option value=cname>Tìm theo họ tên (Ex: nguyenvan a)</option>
					<option value=cmail>Tìm theo email (Ex: abc@gmail.com)</option>
					</select>
					<input name="soption" type="soption">
					<input name="submit" type="submit" value="LookUp">
				</form><br><br>
				<form action="?do=sdate" method="POST" name="sdate">
					Tìm theo ngày/tháng/năm (Ex:15/9/2011)
						<input name="sdate" type="sdate" style="width:30px">
						- <input name="smonth" type="smonth"  style="width:30px">
						- <input name="syear" type="syear"  style="width:30px"> 
						<input name="submit" type="submit" value="LookUp">
				</form>
			</td>';
		}
		
		if ($do == sc)
		{
			$search = $_POST['search'];
			$soption = $_POST['soption'];
			$trimmed = trim($soption);
			if (empty($trimmed))
			{
				echo '<td width=60% valign=top>
				<div style="background:#D5D5FF;"><b>Tìm kiếm thông tin khách hàng cá nhân</div><hr>
				Thông tin truy vấn không có. Đề nghị nhập thông tin vào.</td>';
			}
			else
			{ 
				echo '<td width=60% valign=top>
				<div style="background:#D5D5FF;"><b>Tìm kiếm thông tin khách hàng cá nhân</div><hr>
				<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
					<tr><td>  
						<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
										<tr>
											<td width=2%>ID</td>
											<td width=10%>Tên khách hàng</td>
											<td width=8%>sTime</td>
											<td width=24%>Phản hồi/Xử lí</td>
											<td width=7%>Trạng thái</td>
											<td width=7%>Người khởi tạo</td>
											</tr>';
				//Tìm theo tên
				if ($search == cname)
					{		
						$que = mysql_query("Select * from `mantis_care_report_table` where name like \"%$trimmed%\" ORDER BY id DESC");
						while ($row = mysql_fetch_array($que))
						{	
										$i++;
										$id	= $row['id'];
										$name = $row['name'];
										$phone = $row['phone'];
										$email = $row['email'];
										$sex = $row['sex'];
										$address = $row['address'];
										$city = $row['city'];
										$serial = $row['serial'];
										$lo = $row['lo'];
										$object = $row['object'];
										$status = $row['status'];
										$state = $row['state'];
										$confirm = $row['confirm'];
										$process = $row['process'];
										$receiver = $row['receiver'];
										$carer = $row['carer'];
										$start_time = (date("d-m-Y H:i:s",$row['start_time']));	
										echo '<tr>
											<td class='.$state.'>'.$i.'</td>
											<td class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$name.'</a> ['.$phone.']</td>
											<td class='.$state.'>'.$start_time.'</td>
											<td class='.$state.'>'.$confirm.'</td>
											<td class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
											<td class='.$state.'>'.$carer.'</td>					
											</tr>';	
				} 
					}
				
				//Tim theo phone
				if ($search == cphone)
				{
					$que = mysql_query("Select * from `mantis_care_report_table` where phone like \"%$trimmed%\" ORDER BY id DESC");
					while ($row = mysql_fetch_array($que))
					{
							$i++;
							$id	= $row['id'];
							$name = $row['name'];
							$phone = $row['phone'];
							$email = $row['email'];
							$sex = $row['sex'];
							$address = $row['address'];
							$city = $row['city'];
							$serial = $row['serial'];
							$lo = $row['lo'];
							$object = $row['object'];
							$status = $row['status'];
							$state = $row['state'];
							$confirm = $row['confirm'];
							$process = $row['process'];
							$receiver = $row['receiver'];
							$carer = $row['carer'];
							$start_time = (date("d-m-Y H:i:s",$row['start_time']));	
							// Max a last update
							$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
							$resultt = mysql_query($qr) or die(mysql_error());
							$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
							$resultqt = mysql_query($qt) or die(mysql_error());
							// Print out result
							
							echo '<tr>
							<td class='.$state.'>'.$i.'</td>
							<td class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$name.'</a> ['.$phone.']</td>
							<td class='.$state.'>'.$start_time.'</td>
							<td class='.$state.'>'.$confirm.'</td>
							<td class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
							<td class='.$state.'>'.$carer.'</td>					
							</tr>';	
				}
				}
				
				//Tim theo mail
				if ($search == cmail)
				{
						$que = mysql_query("Select * from `mantis_care_report_table` where email like \"%$trimmed%\" ORDER BY id DESC");
						while ($row = mysql_fetch_array($que))
						{
							$i++;
							$id	= $row['id'];
							$name = $row['name'];
							$phone = $row['phone'];
							$email = $row['email'];
							$sex = $row['sex'];
							$address = $row['address'];
							$city = $row['city'];
							$serial = $row['serial'];
							$lo = $row['lo'];
							$object = $row['object'];
							$status = $row['status'];
							$state = $row['state'];
							$confirm = $row['confirm'];
							$process = $row['process'];
							$receiver = $row['receiver'];
							$carer = $row['carer'];
							$start_time = (date("d-m-Y H:i:s",$row['start_time']));	
							echo '<tr>
							<td class='.$state.'>'.$i.'</td>
							<td class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$name.'</a><br> ['.$phone.']</td>
							<td class='.$state.'>'.$start_time.'</td>
							<td class='.$state.'>'.$confirm.'</td>
							<td class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
							<td class='.$state.'>'.$carer.'</td>
							</tr>';	
						}
				}
				
				echo '</td>';
			}	
		}
	
		if ($do == sdate)
		{
			echo '<td width=60% valign=top>
			<div style="background:#D5D5FF;"><b>Tìm kiếm thông tin khách hàng cá nhân</div><hr>
			<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%><tr><td>  
			<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% bgcolor=#CECEFF class=ttt>  
				<tr>
				<td width=2%>ID</td>
				<td width=10%>Tên khách hàng</td>
				<td width=8%>sTime</td>
				<td width=24%>Phản hồi/Xử lí</td>
				<td width=7%>Trạng thái</td>
				<td width=7%>Người khởi tạo</td>
				</tr>';
				$sdate = $_POST['sdate'];
				$smonth = $_POST['smonth'];
				$syear = $_POST['syear'];
		
				$qrdate = mysql_query("
				SELECT * FROM `mantis_care_report_table` 
				WHERE from_unixtime(start_time, '%e') = '$sdate' and 
				from_unixtime(start_time, '%c') = '$smonth' and
				from_unixtime(start_time, '%Y') = '$syear'
				ORDER BY id DESC");
		
				While ($row = mysql_fetch_array($qrdate))
				{
					$i++;
					$id	= $row['id'];
					$name = $row['name'];
					$phone = $row['phone'];
					$email = $row['email'];
					$sex = $row['sex'];
					$address = $row['address'];
					$city = $row['city'];
					$serial = $row['serial'];
					$lo = $row['lo'];
					$object = $row['object'];
					$status = $row['status'];
					$state = $row['state'];
					$confirm = $row['confirm'];
					$process = $row['process'];
					$receiver = $row['receiver'];
					$carer = $row['carer'];
					$start_time = (date("d-m-Y H:i:s",$row['start_time']));	
				
					// Max a last update
					$qr = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by cid"; 
					$resultt = mysql_query($qr) or die(mysql_error());
					$qt = "SELECT MAX(last_updated),last_updated, cid, note, resolver FROM mantis_carenote_table WHERE cid=$id Group by last_updated ORDER BY last_updated DESC LIMIT 0,1"; 
					$resultqt = mysql_query($qt) or die(mysql_error());
					// Print out result
				
					echo '<tr>
					<td class='.$state.'>'.$i.'</td>
					<td class='.$state.'><a href="view_care_report.php?do=view&id='.$id.'">'.$name.'</a><br>['.$phone.']</td>
					<td class='.$state.'>'.$start_time.'</td>
					<td class='.$state.'>'.$confirm.'</td>
					<td class='.$state.'>'.$state.' (<a href="")>'.$receiver.'</a>)</td>
					<td class='.$state.'>'.$carer.'</td>					
					</tr>';	
			}
				echo '</table>';
	
		}
	
		//Show khách hàng Đại lý
		if ($do == viewagent) 
		{
			$req = mysql_query("select * from `mantis_care_report_table` where dt='agent' ORDER BY id DESC limit 0,100");
			echo ' <td width=60% valign=top><html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Seller management Systems</title>
					<link rel="stylesheet" href="css/default.css" type="text/css">
					<title></title> 
					</head>
					<body>	
					<table border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr>
							<td> 
							<table border=1 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100% class=ttt>  
									<tr>
										<td width=2% bgcolor=#CECEFF>ID</td>
										<td width=10% bgcolor=#CECEFF>Tên khách hàng</td>
										<td width=27% bgcolor=#CECEFF>Phản hồi/xử lí</td>
										<td width=7% bgcolor=#CECEFF>sTime</td>
										<td width=7% bgcolor=#CECEFF>Người khởi tạo</td>
										<td width=7% bgcolor=#CECEFF>Hỗ trợ cuối</td>
										</tr>';
							$i = 0;
							while ($row = mysql_fetch_array($req))
							{
								$i++;
								$id	= $row['id'];
								$spcode = $row['spcode'];
								$name = $row['name'];
								$phone = $row['phone'];
								$email = $row['email'];
								$sex = $row['sex'];
								$address = $row['address'];
								$city = $row['city'];
								$serial = $row['serial'];
								$lo = $row['lo'];
								$object = $row['object'];
								$status = $row['status'];
								$state = $row['state'];
								$confirm = $row['confirm'];
								$process = $row['process'];
								$receiver = $row['receiver'];
								$carer = $row['carer'];
								$start_time = (date("d-m-Y H:i:s",$row['start_time']));
								echo '<tr>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.$i.'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$name.' ['.$phone.']</td>
							<td style="border-bottom:1px solid #666666;"><a href="view_care_report.php?do=view&id='.$id.'">'.nl2br($confirm).'</a></td>
							<td style="border-bottom:1px solid #666666;">'.$start_time.'</td>
							<td style="border-bottom:1px solid #666666;">'.$carer.'</td>
							<td style="border-bottom:1px solid #666666;" class="'.$state.'">'.$state.' (<a href="")>'.$receiver.'</a>)</td>
							</tr>';	
									
							}
			echo '			</table><br>			
							</td>
						</tr>
					</table>
					</body>
					</html></td>';
		}
		
		//Quản lí và chăm sóc khách hàng đại lý và CTV
		$action = $_GET['a'];
		$make = $_GET['m'];
		$getid = $_GET['aid'];
		if ($do == managent)
		{
			echo '<br>
				<table style="border:1px solid black;width:100%;height:20px;"class=ttt><tr>
				<td valign=top width=20%>
					<div style="background:#D5D5FF"><b>Danh mục</b></div><hr>
					<a href="?do=managent&a=addagent" title="Thêm đại lý - CTV">Thêm ĐL-CTV</a> <br> 
					<a href="?do=managent&a=lAgent" title="Danh sách đại lý - CTV">Danh sách ĐL-CTV hiện có</a> <br>
					<a href="?do=managent&a=ldAgent" title="Danh sách đại lý - CTV tạm xóa khỏi hệ thống">Danh sách ĐL-CTV tạm xóa</a> <br>
					<a href="?do=managent&a=sAgent" title="Tìm kiếm đại lý - CTV">Tìm kiếm ĐL-CTV</a></td>';
			if ($action == view)
				{
					echo '<td width=60%></td>';
				}
		
		// Thêm đại lý và CTV
			if ($action == addagent)
				{
				
				echo '<td valign=top width=60%>
				<div style="background:#D5D5FF;"> 
				<b><a href="#1">Nhập thông tin ĐL - CTV</a></b></div><hr>
				<table style="border:0px solid black;width:100%;height:50px;">
					<form name="addag" action="?do=managent&a=PutAgentDb" method="post">
					<tr><td width=25%>Tên đại lý/CTV: *</td><td><input name="nagent" type="text" style="width:550px;height:30px;border:2px solid #DADADA;" ></td></tr>
					<tr><td width=25%>Mã đại lý: *</td><td><input name="cagent" type="text" style="height:30px;border:2px solid #DADADA;"></td></tr>
					<tr><td width=25%>Số điện thoại: *</td><td> <input name="pagent" type="text" style="height:30px;border:2px solid #DADADA;">
					Mã vùng: <Select name="zagent" style="border:2px solid #DADADA;height:25px;">
									<option value =default>Chưa xác định</option>
									<option value =angiang>An Giang</option>
									<option value =brvt>Bà rịa vũng tàu</option>
									<option value =bacgiang>Bắc Giang</option>
									<option value =baclieu>bạc liêu</option>
									<option value =baccan>bắc cạn</option>
									<option value =bacninh>bắc ninh</option>
									<option value =bentre>bến tre</option>
									<option value =binhdinh>bình định</option>
									<option value =binhduong>bình dương</option>
									<option value =binhphuoc>bình phước</option>
									<option value =binhthuan>bình thuận</option>
									<option value =camau>cà mau</option>
									<option value =caobang>cao bằng</option>
									<option value =cantho>cần thơ</option>
									<option value =danang>đà nẵng</option>
									<option value =dl>đắk lắk</option>
									<option value =dn>đắk nông</option>
									<option value =dienbien>điện biên</option>
									<option value =dongnai>đồng nai</option>
									<option value =dongthap>đồng tháp</option>
									<option value =gialai>gia lai</option>
									<option value =hagiang>hà giang</option>
									<option value =hanam>hà nam</option>
									<option value =hanoi>hà nội</option>
									<option value =hatinh>hà tĩnh</option>
									<option value =haiduong>hải dương</option>
									<option value =haiphong>hải phòng</option>
									<option value =haugiang>hậu giang</option>
									<option value =hoabinh>hòa bình</option>
									<option value =hcm>hcm</option>
									<option value =hungyen>hưng yên</option>
									<option value =khanhhoa>khánh hòa</option>
									<option value =kiengiang>kiên giang</option>
									<option value =kontum>kon tum</option>
									<option value =laichau>lai châu</option>
									<option value =lamdong>lam dong</option>
									<option value =langson>lạng sơn</option>
									<option value =laocai>lào cai</option>
									<option value =longan>long an</option>
									<option value =namdinh>nam định</option>
									<option value =nghean>nghệ an</option>
									<option value =ninhbinh>ninh bình</option>
									<option value =ninhthuan>ninh thuận</option>
									<option value =phutho>phú thọ</option>
									<option value =phuyen>phú yên</option>
									<option value =quangbinh>quảng bình</option>
									<option value =quangnam>quảng nam</option>
									<option value =quangngai>quảng ngãi</option>
									<option value =quangninh>quảng ninh</option>
									<option value =quangtri>quảng trị</option>
									<option value =soctrang>sóc trăng</option>
									<option value =sonla>sơn la</option>
									<option value =tayninh>tây ninh</option>
									<option value =thaibinh>thái bình</option>
									<option value =thainguyen>thái nguyên</option>
									<option value =thanhhoa>thanh hóa</option>
									<option value =thuathienhue>thừa thiên huế</option>
									<option value =tiengiang>tiền giang</option>
									<option value =travinh>trà vinh</option>
									<option value =tuyenquang>tuyên quang</option>
									<option value =vinhlong>vĩnh long</option>
									<option value =vinhphuc>vĩnh phúc</option>
									<option value =yenbai>yên bái</option>	
								</select>
					</td></tr>
					<tr><td width=25% valign=top>Thông tin bổ sung: </td>
						<td valign=top><textarea name="iagent" type="text" style="width:550px; height:150px;border:2px solid #DADADA;"></textarea><br>
						Ex: Các thông tin liên quan đến đầu mối kĩ thuật, giám đốc hoặc kế toán.
						</td></tr>
					<tr><td width=25%>Pre Sale: </td><td><Select name="sagent" style="border:2px solid #DADADA;height:25px;">
								<option value =dungntp>Nguyễn Thị Phương Dung</option>
								<option value =maintt>Nguyễn Thị Tuyết Mai</option>
								<option value =hangnt>Ngô Thu Hằng</option>
								<option value =thuyltt>Lê Thị Thanh Thủy</option>
								</select> + Chọn PreSale đang care Đại lý này</td></tr>
					<tr><td width=25%></td>
					<td valign=top><input name="checkbox" type="checkbox">Gửi mail cho tôi và presale khi có thông tin phản hồi mới về đại lý</td></tr>
					<tr><td width=25%>Trạng thái *</td><td><Select name="stagent" style="border:2px solid #DADADA;height:25px;">
								<option value =></option>
								<option value =sdept>Still debt (Đang là ĐL/CTV có công nợ)</option>
								<option value =onfire>On fire (Đang là ĐL/CTV không có công nợ)</option>
								<option value =offfire>Off fire (Không còn là ĐL)</option>
								</select> + Chỉ dành cho presale</td></tr>
					<tr><td width=25%></td><td><input name="submit" type="submit" value="submit" style="width:150px;"></td></tr>
				</table></td>';
				}
		
		// Liệt kê các đại lý và CTV
			if ($action == lAgent)
				{
					$reqlAgent = mysql_query("select * from `mantis_careagent_table` WHERE `dAgent` != 'dtemp' ORDER BY agentID ASC");
					echo '<td valign=top width=60%>
					<div style="background:#D5D5FF"><b><font color=red><u>Danh sách ĐL/CTV hiện có</u></font></b></div><hr>
					<table border=0 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr><td> 
							<table border=0 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" class=ttt>  <tr>
								<td bgcolor=#D5D5FF width=4%><b>agentID</td>
								<td bgcolor=#D5D5FF width=30%><b>nAgent</td>
								<td bgcolor=#D5D5FF><b>cAgent</td>
								<td bgcolor=#D5D5FF><b>sAgent</td>
								<td bgcolor=#D5D5FF><b>stAgent</td>
						</tr>';
						while($row = mysql_fetch_array($reqlAgent))
						{
							$agentID = $row['agentID'];
							$nagent = $row['nAgent'];
							$cagent = $row['cAgent'];
							$iagent = $row['iAgent'];
							$sagent = $row['sAgent'];
							$stagent = $row['stAgent'];
							$timeadd = $row['timeadd'];
							$checkmail = $row['checkmail'];
							echo '<tr>
							<td style="border-bottom:1px solid #DADADA;text-align:center">'.$agentID.'</td>
							<td style="border-bottom:1px solid #DADADA;"><a href="?do=managent&a=dAgent&aid='.$agentID.'">'.$nagent.'</a></td>
							<td style="border-bottom:1px solid #DADADA;">'.$cagent.'</td>
							<td style="border-bottom:1px solid #DADADA;">'.$sagent.'</td>
							<td style="border-bottom:1px solid #DADADA;">'.$stagent.'';
							if ($stagent == offfire) { echo '<img src="images/offfire.jpg">';}
							echo'</td>
							</tr>';
						} 	
					echo '</table></td></tr></table></td>';
				}
		
		// Liệt kê các đại lý và CTV đang tạm xóa
			if ($action == ldAgent)
				{
					$reqlAgent = mysql_query("select * from `mantis_careagent_table` WHERE `dAgent` = 'dtemp' ORDER BY agentID ASC");
					echo '<td valign=top width=60%>
					<div style="background:#D5D5FF"><b><font color=red><u>Danh sách ĐL/CTV tạm xóa</u></font></b></div><hr>
					<table border=0 cellspacing=0 cellpadding=0 style="border-collapse:collapse" width=100%> 
						<tr><td> 
							<table border=0 bordercolor=white cellspacing=0 cellpadding=0 style="border-collapse:collapse" class=ttt>  <tr>
								<td bgcolor=#D5D5FF width=4%><b>agentID</td>
								<td bgcolor=#D5D5FF width=30%><b>nAgent</td>
								<td bgcolor=#D5D5FF><b>cAgent</td>
								<td bgcolor=#D5D5FF><b>sAgent</td>
								<td bgcolor=#D5D5FF><b>stAgent</td>
						</tr>';
						while($row = mysql_fetch_array($reqlAgent))
						{
							$agentID = $row['agentID'];
							$nagent = $row['nAgent'];
							$cagent = $row['cAgent'];
							$iagent = $row['iAgent'];
							$sagent = $row['sAgent'];
							$stagent = $row['stAgent'];
							$timeadd = $row['timeadd'];
							$checkmail = $row['checkmail'];
							echo '<tr>
							<td style="border-bottom:1px solid #DADADA;text-align:center">'.$agentID.'</td>
							<td style="border-bottom:1px solid #DADADA;"><a href="?do=managent&a=dAgent&aid='.$agentID.'">'.$nagent.'</a></td>
							<td style="border-bottom:1px solid #DADADA;">'.$cagent.'</td>
							<td style="border-bottom:1px solid #DADADA;">'.$sagent.'</td>
							<td style="border-bottom:1px solid #DADADA;">'.$stagent.'</td>
							</tr>';
						} 	
					echo '</table></td></tr></table></td>';
				}
		
		// Put dữ liệu vào DB
			if ($action == PutAgentDb)
				{
					$nagent = $_POST['nagent'];
					$cagent = $_POST['cagent'];
					$pagent = $_POST['pagent'];
					$zagent = $_POST['zagent'];
					$iagent = $_POST['iagent'];
					$sagent = $_POST['sagent'];
					$stagent = $_POST['stagent'];
					$checkbox = $_POST['checkbox'];
					$timeadd = time();
				
					mysql_query("insert into `mantis_careagent_table` (nAgent, cAgent, pAgent, zAgent, iAgent, sAgent, stAgent, timeadd, checkmail) 											
								values('$nagent','$cagent','$pagent','$zagent','$iagent','$sagent','$stagent','$timeadd','$checkbox')");
				echo '<td valign=top width=60%><div style="border:1px solid black;width:100%;height=30px;" align=center>
				<b>Bạn vừa nhập xong thông tin của Đại lý/CTV.Nhấn vào <a href="?do=managent&a=lAgent">đây</a> để quay lại.</div></td>';
				}
			
		// Xem chi tiết đại lý và CTV
			if ($action == dAgent)
				{  $reqdAgent = mysql_query("select * from `mantis_careagent_table` WHERE agentID='$getid'");
					echo '<td valign=top width=60%><div style="background:#D5D5FF"><b>Thông tin chi tiết của ĐL/CTV </b></div><hr>';
					while($row = mysql_fetch_array($reqdAgent))
						{
							$agentID = $row['agentID'];
							$nagent = $row['nAgent'];
							$cagent = $row['cAgent'];
							$pagent = $row['pAgent'];
							$zagent = $row['zAgent'];
							$iagent = $row['iAgent'];
							$sagent = $row['sAgent'];
							$stagent = $row['stAgent'];
							$dagent = $row['dAgent'];
							$timeadd = $row['timeadd'];
							$checkmail = $row['checkmail'];
							$stime = (date("d-m-Y H:i:s",$row['timeadd']));
							echo '<table>
							<tr><td><b>Name</td><td>'.$nagent.'</td></tr>
							<tr><td><b>Code</td><td>'.$cagent.'</td></tr>
							<tr><td><b>Phone</td><td>'.$pagent.'</td></tr>
							<tr><td><b>Zone</td><td>'.$zagent.'</td></tr>
							<tr><td valign=top><b>Information</td><td>'.nl2br($iagent).'</td></tr>
							<tr><td><b>Presale</td><td>'.$sagent.'</td></tr>
							<tr><td><b>Status</td><td>'.$stagent.'</td></tr>
							<tr><td><b>Temp (Dạng lưu)</td><td>'.$dagent.'</td></tr>
							<tr><td><b>Timeadd</td><td>'.$stime.'</td></tr>
							</table>
							<hr>
							<div> 
							<a href="?do=managent&m=edit&aid='.$getid.'"><img src="images/edit.jpg"></a>  
							<a href="?do=managent&m=del&aid='.$getid.'"><img src="images/delete.jpg"></a>';
							if ($dagent == dtemp) { echo ' <a href="?do=managent&m=restore&aid='.$getid.'"><img src="images/restore.jpg"></a>
							<a href="?do=managent&m=qdel&aid='.$getid.'"><img src="images/rdelete.jpg"></a>';}
							echo '</div><hr>
							<div style="background:#D5D5FF"><b>Các vấn đề phản hồi của ĐL/CTV và hướng giải quyết </b></div><hr>';
							$rcmAgent = mysql_query("select * from `mantis_cmagent_table` WHERE agID='$getid'");
							while ($row = mysql_fetch_array($rcmAgent))
							{
								echo '<div style="">'.nl2br($row['cmagent']).'</div><br><b>'.$row['resolver'].'</b> | <a href="">Del</a><hr>';
							}
							echo '
							<form name="cmagent" action="?do=managent&a=PutcmAgent&aid='.$getid.'" method="post">
							<textarea type=text name=cmagent style="border:2px solid #DADADA;width:550px;height:100px;"></textarea><br>
							<input name="submit" type="submit" value="" style="background:url(images/post.jpg) no-repeat;width:61px;height:24px;">
							';
						} 	
				echo '</td>';
			}
		
		// PutcmAgent
			if ($action == PutcmAgent)
				{
				$cmagent = $_POST['cmagent'];
				$agID = $_GET['aid'];
				$resolver = $t_current_user_name;
				$timeadd = time();
				echo $timeadd;
				mysql_query("INSERT INTO `mantis_cmagent_table` (agID, cmagent, resolver, last_updated) 											
							VALUES('$agID','$cmagent','$resolver','$timeadd')");
				echo '<td width=60% valign=top>Bạn đã comment cho ĐL/CTV. Nhấn vào <a href="?do=managent&a=dAgent&aid='.$getid.'">đây</a> để tiếp tục</td>';
			}
		
		// Edit thông tin ĐL/CTV
			if ($make == edit)
			{	$editAgent = mysql_query("select * from `mantis_careagent_table` WHERE agentID='$getid'");
					echo '<td width=60% valign=top>
					<div style="background:#D5D5FF"><b>Thay đổi thông tin của ĐL/CTV</b></div><hr>';
					while($row = mysql_fetch_array($editAgent))
						{
							$agentID = $row['agentID'];
							$nagent = $row['nAgent'];
							$cagent = $row['cAgent'];
							$pagent = $row['pAgent'];
							$zagent = $row['zAgent'];
							$iagent = $row['iAgent'];
							$sagent = $row['sAgent'];
							$stagent = $row['stAgent'];
							$timeadd = $row['timeadd'];
							$checkmail = $row['checkmail'];
							$stime = (date("d-m-Y H:i:s",$row['timeadd']));
							
							echo '<form name="PostEditAgent" action="?do=managent&m=pea&aid='.$getid.'" method="post">
							<table><tr><td width=25%><b>Tên đại lý/CTV: *</td><td>
							<textarea name="nagent" type="text" style="width:550px;height:30px;border:2px solid #DADADA;">'.$nagent.'</textarea></td></tr>
							<tr><td width=25%><b>Mã đại lý: *</td><td>
							<input name="cagent" type="text" style="height:30px;border:2px solid #DADADA;" value='.$cagent.'></td></tr>
							<tr><td width=25%><b>Số điện thoại: *</td><td>
							<input name="pagent" type="text" style="height:30px;border:2px solid #DADADA;" value='.$pagent.'></td></tr>
							<tr><td width=25%><b>Zone: </td><td>
							<Select name="zagent" style="height:30px;border:2px solid #DADADA;">
									<option value ='.$zagent.'>'.$zagent.'</option>
									<option value =angiang>An Giang</option>
									<option value =bariavungtau>Bà rịa vũng tàu</option>
									<option value =bacgiang>Bắc Giang</option>
									<option value =baclieu>Bạc liêu</option>
									<option value =baccan>Bắc cạn</option>
									<option value =bacninh>Bắc ninh</option>
									<option value =bentre>Bến tre</option>
									<option value =binhdinh>Bình định</option>
									<option value =binhduong>Bình dương</option>
									<option value =binhphuoc>Bình phước</option>
									<option value =binhthuan>Bình thuận</option>
									<option value =camau>Cà Mau</option>
									<option value =caobang>Cao Bằng</option>
									<option value =cantho>Cần Thơ</option>
									<option value =danang>Đà Nẵng</option>
									<option value =daklak>Đắk lắk</option>
									<option value =daknong>Đắk nông</option>
									<option value =dienbien>Điện Biên</option>
									<option value =dongnai>Đồng Nai</option>
									<option value =dongthap>Đồng Tháp</option>
									<option value =gialai>Gia Lai</option>
									<option value =hagiang>Hà Giang</option>
									<option value =hanam>Hà Nam</option>
									<option value =hanoi>Hà Nội</option>
									<option value =hatinh>Hà Tĩnh</option>
									<option value =haiduong>Hải Dương</option>
									<option value =haiphong>Hải Phòng</option>
									<option value =haugiang>Hậu Giang</option>
									<option value =hoabinh>Hòa Bình</option>
									<option value =hcm>HCM</option>
									<option value =hungyen>Hưng Yên</option>
									<option value =khanhhoa>Khánh Hòa</option>
									<option value =kiengiang>Kiên Giang</option>
									<option value =kontum>Kon Tum</option>
									<option value =laichau>Lai Châu</option>
									<option value =lamdong>Lam Đồng</option>
									<option value =langson>Lạng Sơn</option>
									<option value =laocai>Lào Cai</option>
									<option value =longan>Long An</option>
									<option value =namdinh>Nam Định</option>
									<option value =nghean>Nghệ An</option>
									<option value =ninhbinh>Ninh Bình</option>
									<option value =ninhthuan>Ninh Thuận</option>
									<option value =phutho>Phú Thọ</option>
									<option value =phuyen>Phú Yên</option>
									<option value =quangbinh>Quảng Bình</option>
									<option value =quangnam>Quảng Nam</option>
									<option value =quangngai>Quảng ngãi</option>
									<option value =quangninh>Quảng ninh</option>
									<option value =quangtri>Quảng Trị</option>
									<option value =soctrang>Sóc Trăng</option>
									<option value =sonla>Sơn La</option>
									<option value =tayninh>Tây Ninh</option>
									<option value =thaibinh>Thái Bình</option>
									<option value =thainguyen>Thái Nguyên</option>
									<option value =thanhhoa>Thanh Hóa</option>
									<option value =thuathienhue>Thừa thiên huế</option>
									<option value =tiengiang>Tiền Giang</option>
									<option value =travinh>Trà Vinh</option>
									<option value =tuyenquang>Tuyên Quang</option>
									<option value =vinhlong>Vĩnh Long</option>
									<option value =vinhphuc>Vĩnh Phúc</option>
									<option value =yenbai>Yên Bái</option>	
								</select></td></tr>
							<tr><td width=25% valign=top><b>Information: </td><td>
							<textarea name="iagent" type="text" style="width:550px;height:50px;border:2px solid #DADADA;">'.$iagent.' </textarea></td></tr>
							<tr><td><b>Presale</td><td><Select name="sagent"  style="border:2px solid #CCCCCC;height:30px;">
									<option value ='.$sagent.'>'.$sagent.'</option>
									<option value =dungntp>Nguyễn Thị  Phương Dung</option>
									<option value =mailtt>Lê Thị Tuyết Mai</option>
									<option value =hangnt>Ngô Thu Hằng</option>
									<option value =thuyltt>Lê Thị Thanh Thủy</option>
									</select></td></tr>
							<tr><td><b>Status</td><td><Select name="stagent"  style="border:2px solid #CCCCCC;height:30px;">
									<option value ='.$stagent.'>'.$stagent.'</option>
									<option value =sdept>Still debt (Đang là ĐL/CTV có công nợ)</option>
									<option value =onfire>On fire (Đang là ĐL/CTV không có công nợ)</option>
									<option value =offfire>Off fire (Không còn là ĐL)</option>
									</select></td></tr>
							</table>
							<hr>
							<div> <input name="submit" type="submit" value="" style="background:url(images/post.jpg) no-repeat;width:61px;height:24px;"></div><hr>';
						} 	
					echo '</td>';
			}
		
			if ($make == pea)
			{	echo '<td width=60% valign=top>
					<div style="background:#D5D5FF"><b>Thay đổi thông tin của ĐL/CTV</b></div><hr>';
							$nagent = $_POST['nagent'];
							$cagent = $_POST['cagent'];
							$pagent = $_POST['pagent'];
							$zagent = $_POST['zagent'];
							$iagent = $_POST['iagent'];
							$sagent = $_POST['sagent'];
							$stagent = $_POST['stagent'];
							$checkmail = $_POST['checkmail'];
							echo $nagent;
					mysql_query("UPDATE `mantis_careagent_table` SET 
								`nAgent` = '$nagent',`cAgent` = '$cagent',
								`pAgent` = '$pagent',`zAgent` = '$zagent',
								`iAgent` = '$iagent',`sAgent` = '$sagent',
								`stAgent` = '$stagent',`checkmail` = '$checkmail' 
								WHERE `agentID` ='$getid'");
					header('Location: ?do=managent&a=dAgent&aid='.$getid.'');
				echo '</td>';
			}
			
			if ($make == del)
			{	echo '<td width=60% valign=top>';
					mysql_query("UPDATE `mantis_careagent_table` SET `dAgent` ='dtemp' WHERE `agentID` ='$getid' LIMIT 1");
					header('Location: ?do=managent&a=dAgent&aid='.$getid.'');
				echo '</td>';
			}
			
			if ($make == restore)
			{	echo '<td width=60% valign=top>';
					mysql_query("UPDATE `mantis_careagent_table` SET `dAgent` ='otemp' WHERE `agentID` ='$getid' LIMIT 1");
					header('Location: ?do=managent&a=dAgent&aid='.$getid.'');
				echo '</td>';
			}
			
			if ($make == qdel)
			{	echo '<td width=60% valign=top>
					<div style="background:#D5D5FF"><b>Xóa thông tin của ĐL/CTV khỏi danh sách</b></div><hr>
					Bạn có chắc chắn muốn xóa ĐL/CTV này khỏi hệ thống không? <br>
					<a href="?do=managent&m=rdel&aid='.$getid.'">Yes</a> / <a href="do=managent&a=ldAgent">No</a>
					</td>';
			}
			
			if ($make == rdel)
			{	echo '<td width=60% valign=top>';
					mysql_query("DELETE FROM `mantis_careagent_table` WHERE `agentID` = '$getid' LIMIT 1");
					header('Location: ?do=managent&a=ldAgent');
				echo '</td>';
			}
		
		// Tìm kiếm đại lý
		if ($action == sAgent)
			{  }
				echo '<td valign=top>
				<div style="background:#D5D5FF"><b>Số liệu tổng kết</b></div><hr>
				<a href="?do=managent&a=addagent" title="Tổng số ĐL/CTV hiện có">Tổng số ĐL/CTV hiện có: ...</a> <br> 
				<a href="?do=managent&a=addagent" title="Tổng số ĐL/CTV thêm mới">Tổng số ĐL/CTV thêm mới: ...</a> <br> 
				<a href="?do=managent&a=lAgent" title="Tổng số ĐL/CTV đang dư nợ">Tổng số ĐL/CTV đang dư nợ:...</a> <br>
				<a href="?do=managent&a=sAgent" title="Tổng số ĐL/CTV đã off fire">Tổng số ĐL/CTV đã off fire:...</a> <hr>
				<a href="?do=managent&a=sAgent" title="Tổng số ĐL/CTV đã off fire">Tổng số phản hồi của ĐL/CTV trong tháng:...</a> <br>
			</td></tr></table>';
		}
		
		?>
		</td>
		</tr>
	</table>
</div>

<?php
	html_page_bottom();
